package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.service.IProductSpecService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2024-11-12
 */
@Tag(name = "商品规格")
@RestController
@RequestMapping("/productSpec")
public class ProductSpecController extends BaseController {
    @Autowired
    private IProductSpecService productSpecService;
    @Operation(summary = "查询商品规格列表")
    @GetMapping("/list")
    public TableDataInfo list(){
        startPage();
        List<ProductSpec> list=productSpecService.selectProductSpecList();
        return getDataTable(list);
    }
    @Operation(summary = "新增商品规格")
    @PostMapping
    public AjaxResult add(
            @Parameter(description = "商品规格")
            @RequestBody ProductSpec productSpec){
        productSpec.setCreateBy(SecurityUtils.getUsername());
        return toAjax(productSpecService.save(productSpec));
    }
    @Operation(summary = "删除商品规格")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @Parameter(description = "商品规格id列表", example = "[1,2]")
            @PathVariable List<Long> ids){
        return toAjax(productSpecService.removeBatchByIds(ids));
    }
    @Operation(summary = "根据分类id获取商品规格列表")
    @GetMapping("/productSpecList/{categoryId}")
    public AjaxResult selectProductSpecListByCategoryId(
            @Parameter(description = "分类id")
            @PathVariable Long categoryId) {
        return success(productSpecService.selectProductSpecListByCategoryId(categoryId));
    }
}
